<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/inc/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>授权角色给用户组信息信息列表</title>
<%@ include file="/inc/head.jsp"%>
<script type="text/javascript">
	var grid;
	$(function() {
		grid = $('#grid')
				.treegrid(
						{
							title : '',
							url : sy.contextPath + '/sys/resource/treegrid',
							idField : 'id',
							treeField : 'name',
							rownumbers : true,
							pagination : false,
							sortName : 'weight',
							sortOrder : 'asc',
							frozenColumns : [ [ {
								width : '200',
								title : '资源名称',
								field : 'name'
							} ] ],
							columns : [ [
									{
										width : '100',
										title : '资源标识',
										field : 'identity'
									},
									{
										width : '150',
										title : '图标名称',
										field : 'iconCls'
									},
									{
										width : '300',
										title : '资源路径',
										field : 'url',
										formatter : function(value, row) {
											if (value) {
												return sy
														.formatString(
																'<span title="{0}">{1}</span>',
																value, value);
											}
										}
									},
									{
										width : '80',
										title : '权重',
										field : 'weight'
									},
									{
										width : '80',
										title : '状态',
										field : 'show',
										formatter : function(value) {
											if (value) {
												return '可用';
											} else {
												return "不可用";
											}
										}
									},
									{
										title : '操作',
										field : 'action',
										width : '60',
										formatter : function(value, row) {
											var str = '';
											str += sy
													.formatString(
															'<img class="iconImg ext-icon-note_edit" title="编辑" onclick="resource.edit(\'{0}\');"/>',
															row.id);

											str += sy
													.formatString(
															'<img class="iconImg ext-icon-note_delete" title="删除" onclick="resource.del(\'{0}\');"/>',
															row.id);
											return str;
										}
									} ] ],
							toolbar : '#toolbar',
							onBeforeLoad : function(row, param) {
								parent.$.messager.progress({
									text : '数据加载中....'
								});
							},
							onLoadSuccess : function(row, data) {
								$('.iconImg').attr('src', sy.pixel_0);
								parent.$.messager.progress('close');
							}
						});

		resource = {
			create : function() {
				var dialog = sy.modalDialog({
					title : '新增资源信息',
					url : sy.contextPath + '/sys/resource/create',
					buttons : [ {
						text : '保存',
						handler : function() {
							dialog.find('iframe').get(0).contentWindow
									.submitForm(dialog, grid, parent.$);
						}
					} ]
				});
			},
			del : function(id) {
				parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
					var url = "${ctx}/sys/resource/" + id + "/delete";
					if (r) {
						$.post(url, function() {
							grid.datagrid('reload');
						}, 'json');
					}
				});
			},
			edit : function(id) {
				var url = "${ctx}/sys/resource/update/" + id;
				var dialog = sy.modalDialog({
					title : '编辑资源信息',
					url : url,
					buttons : [ {
						text : '修改',
						handler : function() {
							dialog.find('iframe').get(0).contentWindow
									.submitForm(dialog, grid, parent.$);
						}
					} ]
				});

			},
			undoFun : function() {
				var node = grid.treegrid('getSelected');
				if (node) {
					grid.treegrid('collapseAll', node.id);
				} else {
					grid.treegrid('collapseAll');
				}
			},
			redoFun : function() {
				var node = grid.treegrid('getSelected');
				if (node) {
					grid.treegrid('expandAll', node.id);
				} else {
					grid.treegrid('expandAll');
				}

			}
		};
	});
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<table>
			<tr>
				<td><a href="javascript:void(0);" class="easyui-linkbutton"
					data-options="iconCls:'ext-icon-note_add',plain:true"
					onclick="resource.create();">添加</a></td>
				<td><div class="datagrid-btn-separator"></div></td>
				<td><a onclick="resource.redoFun();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'ext-icon-resultset_next'">展开</a><a
					onclick="resource.undoFun();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'ext-icon-resultset_previous'">折叠</a></td>
				<td><div class="datagrid-btn-separator"></div></td>
				<td><a onclick="grid.treegrid('reload');"
					href="javascript:void(0);" class="easyui-linkbutton"
					data-options="plain:true,iconCls:'ext-icon-arrow_refresh'">刷新</a></td>
			</tr>
		</table>

	</div>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
</body>
</html>